package Calculator.Parser;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.regex.Pattern;

public class Utilities {
	
	public static String DIV = "/";
	public static String SUM = "+";
	public static String MUL = "*";
	public static String RES = "-";
	public static Integer DIV_PRECEDENCE = 3;
	public static Integer MUL_PRECEDENCE = 3;
	public static Integer SUM_PRECEDENCE = 2;
	public static Integer RES_PRECEDENCE = 2;
	public static String LEFT_PARENTHESIS = "(";
	public static String RIGHT_PARENTHESIS = ")";
	public static Pattern elementsPattern = Pattern.compile("\\s*((?:\\d+|[+*/()-]))\\s*", 
			Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
	public static Pattern numberPattern = Pattern.compile("([\\d]+)", 
			Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
	public static Pattern operatorPattern = Pattern.compile("([+*/-])", 
			Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
	public static Pattern parenthesisPattern = Pattern.compile("([()])", 
			Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
	public static Pattern wrongExpressionPattern = Pattern.compile("([^0-9\\s+*/)(-])", 
			Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
	
	public static double roundToTwoDecimals(double d) {
	    BigDecimal bd = new BigDecimal(d);
	    bd = bd.setScale(2, RoundingMode.DOWN);
	    return bd.doubleValue();
	}
}
